<?xml version="1.0" encoding="utf-8"?>
<UserControl x:Class="Jonathan.Interface.WikiUpload"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             Loaded="WikiUploadLoaded">
   <UserControl.Resources>
      <ResourceDictionary>
         <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/Monti;component/Themes/Common.xaml" />
         </ResourceDictionary.MergedDictionaries>
      </ResourceDictionary>
   </UserControl.Resources>
   <UserControl.Background>
      <StaticResourceExtension ResourceKey="MetroBaseBackground" />
   </UserControl.Background>
   <Grid Margin="10">
      <Grid.RowDefinitions>
         <RowDefinition Height="Auto" />
         <RowDefinition Height="Auto" />
         <RowDefinition Height="*" />
         <RowDefinition Height="100px" />
      </Grid.RowDefinitions>
      <GroupBox Header="Action">
         <Grid>
            <Grid.ColumnDefinitions>
               <ColumnDefinition Width="150px" />
               <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            
            <ComboBox Grid.Column="0"
                      SelectedIndex="0"
                      SelectedValue="{Binding Path=SelectedAction}"
                      ItemsSource="{Binding Path=Actions}"
                      VerticalContentAlignment="Center" />
            
            <Grid Grid.Column="1"
                  Visibility="{Binding Path=IsSaveFileGridVisible, Converter={StaticResource boolConverter}}">
               <Grid.ColumnDefinitions>
                     <ColumnDefinition Width="Auto" />
                     <ColumnDefinition Width="*" />
                     <ColumnDefinition Width="Auto" />
               </Grid.ColumnDefinitions>
               <TextBlock Text="File to save data to:"
                          Margin="4"
                          Grid.Column="0" />
               <TextBox Margin="4"
                        Text="{Binding Path=SaveFile}"
                        Grid.Column="1" />
               <Button Margin="4"
                       Content="Browse"
                       Grid.Column="2"
                       CommandParameter="SaveFile"
                       Command="{Binding Path=ActionCommand}"
                       Width="75px"/>
            </Grid>
            
            <Grid Grid.Column="1"
                  Visibility="{Binding Path=IsLoginGridVisible, Converter={StaticResource boolConverter}}">
               <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="Auto" />
                  <ColumnDefinition Width="*" />
                  <ColumnDefinition Width="Auto" />
                  <ColumnDefinition Width="*" />
               </Grid.ColumnDefinitions>
               <TextBlock Text="User:"
                          Margin="4"
                          Grid.Column="0" />
               <TextBox Margin="4"
                        MaxWidth="250px"
                        Text="{Binding Path=Options.Configuration.WikiUserName}"
                        Grid.Column="1" />
               <TextBlock Text="Password:"
                          Margin="4"
                          Grid.Column="2" />
               <PasswordBox Margin="4"
                            Grid.Column="3"
                            MaxWidth="250px"
                            x:Name="_Password"
                            PasswordChanged="PasswordChanged" />
            </Grid>
         </Grid>
      </GroupBox>
      <StackPanel Orientation="Horizontal"
                  Grid.Row="1"
                  HorizontalAlignment="Center"
                  Visibility="{Binding Path=IsInputGridVisible, Converter={StaticResource boolConverter}}">
         <ToggleButton Content="Page"
                       IsChecked="{Binding Path=IsPage}"
                       Style="{StaticResource MetroToggleButton}" />
         <ToggleButton Content="Excerpt"
                       IsChecked="{Binding Path=IsExcerpt}"
                       Style="{StaticResource MetroToggleButton}" />
         <ToggleButton Content="Chapter"
                       IsChecked="{Binding Path=IsChapter}"
                       Style="{StaticResource MetroToggleButton}" />
      </StackPanel>
      
      <Grid Grid.Row="2"
            Visibility="{Binding Path=IsUploadFileGridVisible, Converter={StaticResource boolConverter}}">
         <Grid.ColumnDefinitions>
               <ColumnDefinition Width="Auto" />
               <ColumnDefinition Width="*" />
               <ColumnDefinition Width="Auto" />
         </Grid.ColumnDefinitions>
         
         <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
         </Grid.RowDefinitions>
         
         <TextBlock Text="File with wiki data:"
                    Margin="4"
                    Grid.Row="0"
                    Grid.Column="0" />
         <TextBox Margin="4"
                  Grid.Row="0"
                  Grid.Column="1"
                  Text="{Binding Path=SaveFile}" />
         <Button Margin="4"
                 Grid.Row="0"
                 Grid.Column="2"
                 Content="Browse"
                 CommandParameter="OpenFile"
                 Command="{Binding Path=ActionCommand}"
                 Width="75px"/>
         
         <Button Margin="4"
                 Grid.Row="1"
                 Grid.Column="1"
                 Content="Upload"
                 HorizontalAlignment="Center"
                 CommandParameter="UploadFile"
                 Command="{Binding Path=ActionCommand}"
                 Width="75px"/>
         
         <TextBlock Text="This operation will upload the content of the given file directly to the wiki. If any of the pages
in the file exist on the wiki, they will be overwritten.&#10;The structure of the file is:&#10;
[Wiki Page Title]&#10;
[Wiki Page Content]&#10;
Blank Line&#10;
[Wiki Page Title]&#10;
[Wiki Page Content]&#10;
Blank Line&#10;
..."
                    TextWrapping="Wrap"
                    HorizontalAlignment="Left"
                    Margin="4"
                    Grid.Row="2"
                    Grid.Column="0"
                    Grid.ColumnSpan="3" />
      </Grid>
      
      <Grid Grid.Row="2"
            Visibility="{Binding Path=IsInputGridVisible, Converter={StaticResource boolConverter}}">
         <Grid.ColumnDefinitions>
            <ColumnDefinition Width=".6*" />
            <ColumnDefinition Width=".4*" />
         </Grid.ColumnDefinitions>
         <Grid Grid.Column="0">
            <Grid.ColumnDefinitions>
               <ColumnDefinition Width="Auto" />
               <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
               <RowDefinition Height="Auto" />
               <RowDefinition Height="Auto" />
               <RowDefinition Height="Auto" />
               <RowDefinition Height="Auto" />
               <RowDefinition Height="Auto" />
               <RowDefinition Height="Auto" />
               <RowDefinition Height="*" />
               <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid Grid.Row="0"
                  Grid.ColumnSpan="2">
               <Grid.RowDefinitions>
                  <RowDefinition Height="Auto" />
                  <RowDefinition Height="Auto" />
               </Grid.RowDefinitions>
               <StackPanel Grid.Row="0"
                           Orientation="Horizontal">
                  <Button Click="CenterClick"
                          ToolTip="Center">
                     <Image Source="/Jonathan;component/Images/text_align_center.png"
                            Width="16px"
                            Height="16px" />
                  </Button>
                  <Button Click="SmallClick"
                          ToolTip="Small">
                     <Image Source="/Jonathan;component/Images/text_smallcaps.png"
                            Width="16px"
                            Height="16px" />
                  </Button>
                  <Button Click="BoldClick"
                          ToolTip="Bold">
                     <Image Source="/Jonathan;component/Images/text_bold.png"
                            Width="16px"
                            Height="16px" />
                  </Button>
                  <Button Click="ItalicClick"
                          ToolTip="Italic">
                     <Image Source="/Jonathan;component/Images/text_italic.png"
                            Width="16px"
                            Height="16px" />
                  </Button>
                  <Button Click="LinkClick"
                          ToolTip="Create Link">
                     <Image Source="/Jonathan;component/Images/link.png"
                            Width="16px"
                            Height="16px" />
                  </Button>
                  <Button Click="BreakClick"
                          ToolTip="Add line break">
                     <Image Source="/Jonathan;component/Images/red_line.png"
                            Width="16px"
                            Height="16px" />
                  </Button>
                  <CheckBox Content="Fix breaks"
                            x:Name="_FixBreaks"
                            Margin="2,0,0,0"
                            VerticalAlignment="Center"
                            VerticalContentAlignment="Center"
                            IsChecked="{Binding Path=ReplaceLineBreaks}" />
                  <ComboBox SelectedValue="{Binding Path=BreakReplacement}"
                            ItemsSource="{Binding Path=BreakReplacements}"
                            Margin="2,0,0,0"
                            IsEnabled="{Binding Path=IsChecked, ElementName=_FixBreaks}" />
               </StackPanel>
               <StackPanel Grid.Row="1"
                           Orientation="Horizontal"
                           Margin="0,5,0,0">
                  <Button Click="OtherLinkClick"
                          ToolTip="Create other link">
                     <Image Source="/Jonathan;component/Images/link_go.png"
                            Width="16px"
                            Height="16px" />
                  </Button>
                  <ComboBox x:Name="_cmbOtherLink"
                            Width="150px"
                            Margin="2,0,0,0" />
                  <TextBox x:Name="_txtWikipedia"
                           Margin="2,0,0,0"
                           Width="150px" />
                  <Button Click="RefreshOtherLinks"
                          ToolTip="Refresh other links">
                     <Image Source="/Jonathan;component/Images/arrow_refresh.png"
                            Width="16px"
                            Height="16px" />
                  </Button>
                  <Button Click="AddOtherLinks"
                          ToolTip="Add to other links list">
                     <Image Source="/Jonathan;component/Images/page_add.png"
                            Width="16px"
                            Height="16px" />
                  </Button>
               </StackPanel>
            </Grid>
            <TextBlock Text="Book:"
                       Margin="3"
                       Grid.Row="1"
                       Grid.Column="0" />
            <TextBox Text="{Binding Path=Book, UpdateSourceTrigger=PropertyChanged}"
                     Grid.Row="1"
                     Margin="3"
                     Grid.Column="1" />
            <TextBlock Text="Chapter:"
                       Margin="3"
                       Grid.Row="2"
                       Grid.Column="0" />
            <Grid Grid.Row="2"
                  Grid.Column="1">
               <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="20px" />
                  <ColumnDefinition Width="*" />
                  <ColumnDefinition Width="20px" />
               </Grid.ColumnDefinitions>
               <Button Content="-"
                       Height="20px"
                       VerticalAlignment="Center"
                       Grid.Column="0"
                       Command="{Binding Path=ActionCommand}"
                       CommandParameter="ChapterMinus" />
               <TextBox Text="{Binding Path=Chapter, UpdateSourceTrigger=PropertyChanged}"
                        Margin="3"
                        Grid.Column="1" />
               <Button Content="+"
                       Height="20px"
                       VerticalAlignment="Center"
                       Grid.Column="2"
                       Command="{Binding Path=ActionCommand}"
                       CommandParameter="ChapterPlus" />
            </Grid>
            <TextBlock Text="Verse:"
                       Margin="3"
                       Grid.Row="3"
                       Grid.Column="0" />
            <Grid Grid.Row="3"
                  Grid.Column="1">
               <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="20px" />
                  <ColumnDefinition Width="*" />
                  <ColumnDefinition Width="20px" />
               </Grid.ColumnDefinitions>
               <Button Content="-"
                       Height="20px"
                       VerticalAlignment="Center"
                       Grid.Column="0"
                       Command="{Binding Path=ActionCommand}"
                       CommandParameter="VerseMinus" />
               <TextBox Text="{Binding Path=Verse, UpdateSourceTrigger=PropertyChanged}"
                        Margin="3"
                        Grid.Column="1" />
               <Button Content="+"
                       Height="20px"
                       VerticalAlignment="Center"
                       Grid.Column="2"
                       Command="{Binding Path=ActionCommand}"
                       CommandParameter="VersePlus" />
            </Grid>
            <TextBlock Text="Header:"
                       VerticalAlignment="Top"
                       Margin="3"
                       Grid.Row="4"
                       Grid.Column="0" />
            <CheckBox Content="To Footer"
                      Margin="3,24,0,0"
                      Grid.Row="4"
                      Grid.Column="0"
                      IsChecked="{Binding Path=CopyHeaderToFooter}" />
            <TextBox Grid.Row="4"
                     MinLines="3"
                     Grid.Column="1"
                     FontSize="16"
                     TextWrapping="Wrap"
                     FontFamily="Consolas"
                     AcceptsReturn="True"
                     x:Name="_TxtHeader"
                     Margin="3"
                     GotFocus="TxtFocused"
                     VerticalScrollBarVisibility="Auto"
                     Grid.ColumnSpan="2"
                     Text="{Binding Path=Header, UpdateSourceTrigger=PropertyChanged}" />
            <TextBlock Text="Footer:"
                       VerticalAlignment="Top"
                       Margin="3"
                       Grid.Row="5"
                       Grid.Column="0" />
            <TextBox Grid.Row="5"
                     Grid.Column="1"
                     FontSize="16"
                     MinLines="3"
                     TextWrapping="Wrap"
                     FontFamily="Consolas"
                     AcceptsReturn="True"
                     x:Name="_TxtFooter"
                     Margin="3"
                     GotFocus="TxtFocused"
                     VerticalScrollBarVisibility="Auto"
                     Grid.ColumnSpan="2"
                     Text="{Binding Path=Footer, UpdateSourceTrigger=PropertyChanged}" />
            <TextBlock Text="Passage:"
                       VerticalAlignment="Top"
                       Margin="3"
                       Grid.Row="6"
                       Visibility="{Binding Path=IsExcerpt, Converter={StaticResource boolConverter}}"
                       Grid.Column="0" />
            <TextBlock Grid.Row="6"
                       FontSize="14"
                       HorizontalAlignment="center"
                       Text="To change contents, type directly in the content box -->"
                       Grid.Column="1" />
            <TextBox Grid.Row="6"
                     Grid.Column="1"
                     FontSize="16"
                     TextWrapping="Wrap"
                     FontFamily="Consolas"
                     AcceptsReturn="True"
                     x:Name="_TxtPassage"
                     Margin="3"
                     GotFocus="TxtFocused"
                     VerticalScrollBarVisibility="Auto"
                     Grid.ColumnSpan="2"
                     Visibility="{Binding Path=IsExcerpt, Converter={StaticResource boolConverter}}"
                     Text="{Binding Path=Passage, UpdateSourceTrigger=PropertyChanged}" />

            <StackPanel Grid.Row="7"
                        Grid.ColumnSpan="2"
                        Orientation="Horizontal"
                        HorizontalAlignment="Center">
               <Button Width="150px"
                       Content="Clear"
                       Command="{Binding Path=ActionCommand}"
                       CommandParameter="Clear" />
               <Button Width="150px"
                       Margin="10,0,10,0"
                       Content="{Binding Path=UploadButtonText}"
                       Command="{Binding Path=ActionCommand}"
                       CommandParameter="Upload" />
            
               <CheckBox IsChecked="{Binding Path=UploadChapter}">
                  <CheckBox.Resources>
                     <Style TargetType="CheckBox">
                        <Setter Property="Content" Value="Upload Chapter" />
                        <Setter Property="Visibility" Value="Collapsed" />
                        <Setter Property="VerticalAlignment" Value="Center" />
                        <Setter Property="VerticalContentAlignment" Value="Center" />
                        <Style.Triggers>
                           <MultiDataTrigger>
                              <MultiDataTrigger.Conditions>
                                 <Condition Binding="{Binding Path=IsExcerpt}" Value="True"/>
                                 <Condition Binding="{Binding Path=UploadButtonText}" Value="Upload to Wiki"/>
                              </MultiDataTrigger.Conditions>
                              <MultiDataTrigger.Setters>
                                 <Setter Property="Visibility"
                                         Value="Visible" />
                              </MultiDataTrigger.Setters>
                           </MultiDataTrigger>
                        </Style.Triggers>
                     </Style>
                  </CheckBox.Resources>
               </CheckBox>
            </StackPanel>
         </Grid>
         <Grid Grid.Column="1">
            <Grid.ColumnDefinitions>
               <ColumnDefinition Width="Auto" />
               <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
               <RowDefinition Height="Auto" />
               <RowDefinition Height="Auto" />
               <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <TextBlock VerticalAlignment="Center"
                       Text="Page Title:"
                       Margin="3"
                       Grid.Row="0"
                       Grid.Column="0" />
            <TextBox Text="{Binding Path=PageTitle}"
                     Margin="3"
                     Grid.Row="0"
                     Grid.Column="1" />
            <TextBlock Text="Wiki Content:"
                       HorizontalAlignment="Center"
                       Margin="3"
                       Grid.Row="1"
                       Grid.ColumnSpan="2" />
            <TextBox Grid.Row="2"
                     FontSize="16"
                     TextWrapping="Wrap"
                     FontFamily="Consolas"
                     AcceptsReturn="True"
                     x:Name="_TxtWikiContent"
                     Margin="3"
                     GotFocus="TxtFocused"
                     VerticalScrollBarVisibility="Auto"
                     Grid.ColumnSpan="2"
                     Text="{Binding Path=WikiContent, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />
         </Grid>
      </Grid>
      <Grid Grid.Row="3"
            Margin="5">
         <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
         </Grid.RowDefinitions>

         <StackPanel Grid.Row="0"
                     Orientation="Horizontal">
            <Button Command="{Binding Path=ActionCommand}"
                    ToolTip="Clear Log"
                    CommandParameter="ClearLog">
               <Image Source="/Jonathan;component/Images/draw_eraser.png"
                      Width="16px"
                      Height="16px" />
            </Button>
         </StackPanel>

         <TextBox IsReadOnly="True"
                  Text="{Binding Path=Log}"
                  TextWrapping="Wrap"
                  Name="_LogTextBox"
                  Grid.Row="1"
                  FontFamily="Consolas"
                  VerticalScrollBarVisibility="Auto" />
      </Grid>
   </Grid>
</UserControl>